<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	Long sysMills = System.currentTimeMillis();
	request.setAttribute("sysMills", sysMills);
%>
<table class="display" id="example">
	<thead>
		<tr>
			<th style="text-align: left; width: 20px"></th>
			<th style="width: 19%">自定义薪资方案名称</th>
			<th>方案计算公式</th>
			<th style="width: 7%">人数</th>
			<th style="width: 7%">状态</th>
			<th style="width: 70px">操作</th>
			<th style="width: 70px">设定人员</th>
		</tr>
	</thead>
	<tbody>
		<s:if test="#request.customs==null || #request.customs.size<=0">
			<tr class="gradeA">
				<td colspan="7">暂无数据</td>
			</tr>
		</s:if>
		<s:else>
			<s:iterator var="custom" status="sta" value="#request.customs">
				<s:if test="#sta.even">
					<tr class="gradeA">
				</s:if>
				<s:else>
					<tr class="gradeC">
				</s:else>
				<td><input type="checkbox" name="chk_custom"
					value="${custom.id}" /></td>
				<td>${custom.projectTitle}</td>
				<td><s:if
						test="#custom.details == null || #custom.details.size <=0">
						暂无
					</s:if> <s:else>
						<s:iterator var="detail" status="st" value="#custom.details">
							<a class="button" href="javascript:void(0)"><span
								style="background: url(${ctx}/images/img/chart_bar_edit.png)"
								class="icon">&nbsp;</span>${detail.schemeTitle}</a>
						</s:iterator>
					</s:else></td>
				<td name="td_employeenumber" title="${custom.id}"></td>
				<td>
					<s:if test="#custom.startDate.time > #request.sysMills">未开始</s:if>
					<s:elseif test="#custom.startDate.time <= #request.sysMills && #custom.endDate.time >= #request.sysMills">进行中</s:elseif>
					<s:else>已结束</s:else>
				</td>
				<td><a class="button" href="#salary/custom_manage.xhtml?customId=${custom.id}"><span
						style="background: url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>修改</a></td>
				<td><a class="button" href="#salary/custom_user_setting.xhtml?customId=${custom.id}&organizationId=${organizationId}"><span
						style="background: url(${ctx}/images/img/user_add.png)" class="icon">&nbsp;</span>设定</a></td>
				</tr>
			</s:iterator>
		</s:else>
	</tbody>
</table>
<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp"%>
</p>
<div class="tabs side grid_12 leading">

	<div class="clear"></div>
	<div class="grid_12">


		<div class="form-action clearfix">
			<p>
				<input type="checkbox" value="1" id="form-updates-i2"
					onchange="checkAll(this,'chk_custom')" /><label
					for="form-updates-i2">全选</label> <a class="button"
					href="javascript:void(0)" onclick="deleteDatas('chk_custom')"><span
					style="background: url(${ctx}/images/img/cancel.png)" class="icon">&nbsp;</span>批量删除</a>
				<a class="button"
					href="#salary/custom_manage.xhtml?organizationId=${organizationId}"><span
					style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加方案</a>
			</p>
		</div>
	</div>
</div>

<script type="text/javascript">

	$(document).ready(function(){
		$("td[name='td_employeenumber']").each(function(i){
			loadEmployeeNumber(this,$(this).attr("title"));
		});
	});
	
	function loadEmployeeNumber(obj,customId){
		$.ajax({
	        type:"get",
	        url:"/ajax/query_employeeofcustomid.xhtml?customId=" + customId,
	        //data: "name=John&location=Boston",
	        dataType:"json",
	        success:function (data) {
	    		 if (data != null) {
	    			 $(obj).html(data);
	    		 }
	        }
	    });
	}

	/**
	* 删除数据
	*/
	function deleteDatas(name) {
		var checkIds = new Array();
		$("input[type='checkbox'][name='" + name + "']").each(function() {
			if (this.checked) {
				checkIds.push(this.value);
			}
		});
		if (checkIds.length == 0) {
			return;
		}
		if (confirm("确定要删除选中的数据吗？")) {
			doDeleteDatas("${ctx}/salary/custom_delete.xhtml",checkIds.join(","));
		}
	}
	
	/**
	 * 删除指定数据集
	 * @param url
	 * @param ids
	 */
	function doDeleteDatas(url,ids) {
		$.ajax({
			type : "get",
			url : url,
			data: {"ids":ids},
			dataType : "json",
			success : function(data) {
				// load the grade list
				//currentTabOrgId
				if(typeof(currentTabOrgId) == 'number'){
					loadListContent("${ctx}${listAction}", currentTabOrgId);
				}else{
					loadListContent("${ctx}${listAction}",${organizationId});
				}
			}
		});
	}

	

	
</script>